package com.link.wseller.mapper;

import com.link.wseller.domain.ProductInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface ProductInfoMapper {
    @Delete({
        "delete from product_info",
        "where product_id = #{productId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String productId);

    @Insert({
        "insert into product_info (product_id, product_name, ",
        "product_price, product_stock, ",
        "product_description, product_icon, ",
        "product_status, category_type, ",
        "create_time, update_time)",
        "values (#{productId,jdbcType=VARCHAR}, #{productName,jdbcType=VARCHAR}, ",
        "#{productPrice,jdbcType=DECIMAL}, #{productStock,jdbcType=INTEGER}, ",
        "#{productDescription,jdbcType=VARCHAR}, #{productIcon,jdbcType=VARCHAR}, ",
        "#{productStatus,jdbcType=TINYINT}, #{categoryType,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(ProductInfo record);

    @InsertProvider(type=ProductInfoSqlProvider.class, method="insertSelective")
    int insertSelective(ProductInfo record);

    @Select({
        "select",
        "product_id, product_name, product_price, product_stock, product_description, ",
        "product_icon, product_status, category_type, create_time, update_time",
        "from product_info",
        "where product_id = #{productId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="product_id", property="productId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR),
        @Result(column="product_price", property="productPrice", jdbcType=JdbcType.DECIMAL),
        @Result(column="product_stock", property="productStock", jdbcType=JdbcType.INTEGER),
        @Result(column="product_description", property="productDescription", jdbcType=JdbcType.VARCHAR),
        @Result(column="product_icon", property="productIcon", jdbcType=JdbcType.VARCHAR),
        @Result(column="product_status", property="productStatus", jdbcType=JdbcType.TINYINT),
        @Result(column="category_type", property="categoryType", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    ProductInfo selectByPrimaryKey(String productId);

    @UpdateProvider(type=ProductInfoSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(ProductInfo record);

    @Update({
        "update product_info",
        "set product_name = #{productName,jdbcType=VARCHAR},",
          "product_price = #{productPrice,jdbcType=DECIMAL},",
          "product_stock = #{productStock,jdbcType=INTEGER},",
          "product_description = #{productDescription,jdbcType=VARCHAR},",
          "product_icon = #{productIcon,jdbcType=VARCHAR},",
          "product_status = #{productStatus,jdbcType=TINYINT},",
          "category_type = #{categoryType,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where product_id = #{productId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(ProductInfo record);
}